package com.ruoyi.activiti.controller;

import com.ruoyi.activiti.domain.CustomProcess;
import com.ruoyi.activiti.service.ICustomProcessService;
import com.ruoyi.activiti.service.ICustomProcessServiceHis;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("自定义流程引擎")
@RestController
@RequestMapping("/custom/process/history")
@AllArgsConstructor
public class CustomProcessHisController extends BaseController {
    @Autowired
    private ICustomProcessServiceHis customProcessService;

    @ApiOperation("获取定义的流程列表")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody CustomProcess process)
    {
        startPage();
        List<CustomProcess> list = customProcessService.selectList(process);
        return getDataTable(list);
    }
    @ApiOperation("保存流程")
    @PostMapping("/saveProcess")
    public AjaxResult saveProcess(@RequestBody CustomProcess process){
        customProcessService.saveProcess(process);
        return AjaxResult.success();
    }
    @ApiOperation("更新流程")
    @PostMapping("/updateProcess")
    public AjaxResult updateProcess(@RequestBody CustomProcess process){
        customProcessService.updateProcess(process);
        return AjaxResult.success();
    }
    @ApiOperation("删除流程")
    @GetMapping("/delete")
    public AjaxResult delete(Long id) {
        customProcessService.deleteProcess(id);
        return AjaxResult.success();
    }
    @ApiOperation("通过主键获取流程详情")
    @GetMapping("/getProcessInfo")
    public AjaxResult getProcessInfo(Long id) {
        CustomProcess process = customProcessService.selectById(id);
        return AjaxResult.success(process);
    }
    @ApiOperation("通过主键获取流程详情通过流程定义id")
    @GetMapping("/getProcessInfoByDefId")
    public AjaxResult getProcessInfoByDefId(String procDefId) {
        CustomProcess process = customProcessService.selectByProcDefId(procDefId);
        return AjaxResult.success(process);
    }
}
